home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 3
/
Gold Medal Software - Volume 3 (Gold Medal) (1994).iso
/
prog
/
proxy14.arj
/
H3.HLP
< prev
next >
Wrap
Text File
|
1992-12-05
|
6KB
|
154 lines
STATEMENTS
left-hand-value = expr ; simple assignment, map update,
if ( expr ) stat1 conditional statement - form1
if ( expr ) stat1 ; conditional statement - form2
else stat2
while ( expr ) stat while statement
for iden <- expr ; stat for statament
return ; return statement - form1
return expr; return statement - form2
iden ( expr-list ); function call
{ stat1 ; ... statn ; } block
open(iden,"r") ; open read statement
open(iden,"w") ; open write statement
close(iden) ; close statement
readln(v1,...,vn) ; readln statement
readln(iden,v1,...vn) ; readln file statement
writeln(v1,...,vn) ; writeln statement
writeln(iden,v1,...,vn) ; writeln file statement
A statement is either a simple statement or a block (see below),
which is a sequence of statements delimited by curly brackets.
Assignment Statement
identifier = expression ; expression is evaluated and the
resulting value is stored in
identifier. Examples are:
x = {2, 3, 5, 7} ; simple assignment
m["Joe"] = 30; map update
p.r = {1->2, 3->4}; struct update
Conditional Statement
The conditional or if-statement may take one of the following
forms:
if ( expr ) stat1 in both cases, expr is evaluated;
if it evaluates to true then stat1
if ( expr ) stat1 ; else stat2 is executed. If it evaluates to
false, in the first case nothing
happens; in the second case stat2
is executed. Examples are:
if (x < 2) y = 0;
if (n == 0 ) f = 1; else f = n * f;
While statement
while ( expr ) stat expr is evaluated; as long as its
value is true, stat is executed,
and expr is reevaluated; when its
value is false, the following
statement is executed. Example:
while (n <= 10) n=n+1;
For statement
for identifier <- expr ; stat expr is evaluated and identifier
is assigned the values of the
resulting set or sequence; stat
is executed for each of these
assignments. Example:
for i <- {1..10}; writeln(i);
Return statement
The return statement may take one of the following forms:
return ; the enclosing function is terminated.
return expr ; expr is evaluated and the enclosing
function is terminated with the value
of expr as its returned value. Example
return n+1;
I/O statements:
open(string,"r"); Opens a file for reading given by
string, and returns a file handle.
h = open("data.txt","r");
open(string,"w") ; Opens a file for writing given by
string, and returns a file handle.
close(identifier) ; Closes the file whose handle is
given by identifier.
close(h);
writeln(v1,...,vn) ; The scalar values or scalar valued
variables vi (integer, real, string,
boolean) are printed on one line
separated by spaces.
writeln(123,r,"order");
writeln(identifier,v1,...,vn) ; The values v1,...vn are output to
the file whose handle is given by
identifier.
writeln(h,123,r,"order");
readln(v1,...,vn) ; The variables v1,...vn (which must be
global) are assigned the corresponding
values input at the keyboard.
readln(a,b,c);
readln(identifier,v1,...vn) ; The variables v1,...vn are assigned
the corresponding values in the file
whose handle is given by identifier.
If there are no more values in the file
to read, the global variable eof has
the value true, otherwise it has the
value false.
fun() {readln(h,a,b,c);
while(!eof) {writeln(a,b,c);
readln(h,a,b,c);}
};
Function call
identifier ( expr-list ) ; Each expr in expr-list is evaluated
and the function represented by
identifier is called with the
resulting arguments. If the function
call is not contained in an expression
i.e. it appears in a statement
context, the resulting value is
discarded.
Block
A sequence of statements may be grouped together to form a block
by enclosing them within curly brackets:
{ stat1 ;
stat2 ;
...
statn ;
} Notice that there is no semi-colon
after the closing bracket. Example:
while (bal>0) {int=bal*r;am=pay-int;bal=bal-am;n=n+1;}